<template>
    <div class="header">
        <div>
            <span>ToDoList</span>
            <input type="text" @keyup.enter="addTask(task)" v-model="task" placeholder="添加todo" />
        </div>
    </div>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
    name: '',
    data() { 
        return {
            task: ''
        }
    },
    created() {
        console.log(this);
    },
    methods:{
        // 添加任务的逻辑
        // addTask() {
        //     this.$store.commit('addTask', this.task)
        //     this.task = ''
        // }
        ...mapMutations(['addTask'])
    },
}
</script>

<style scoped lang="scss">
.header {
    width: 100%;
    height: 70px;
    background-color: #333;
    color: #fff;
    div {
        width: 600px;
        margin: 0 auto;
        height: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        span {
            font-size: 30px;
            font-weight: bold;
        }
        input {
            border: none;
            border-radius: 6px;
            background-color: #fff;
            width: 350px;
            height: 30px;
            padding-left: 10px;
            outline: none;
        }
    }
}
</style>